﻿@{
    Layout = "~/Views/Shared/_Layout.cshtml";
    ViewData["Title"] = Model.ArticleDetailModel.Title + "-一起牛";
    ViewData["keywords"] = Model.ArticleDetailModel.KeyWord;
    ViewData["Description"] = Model.ArticleDetailModel.Summary;
}
@model ArticleDetailVM
@section css{
    <link href="~/css/prettify.min.css" rel="stylesheet" asp-append-version="true" />
    <link href="~/css/layer.css" rel="stylesheet" asp-append-version="true" />
    <link href="~/css/prism.css" rel="stylesheet" asp-append-version="true" />
}
@section js{
    <script src="~/js/prettify.js" asp-append-version="true"></script>
    <script src="~/js/run_prettify.js" asp-append-version="true"></script>
    <script src="~/js/layer.js" asp-append-version="true"></script>
    <script src="~/js/prism.js" asp-append-version="true"></script>
}
<script>
    prettyPrint();
</script>

<div class="lbox">
    <div class="content_box whitebg">
        <h2 class="htitle"><span class="con_nav">您现在的位置是：<a href="/">首页</a>&nbsp;&gt;&nbsp;<a href="@domainConfig.CurrentValue.Host@Url.Action("newsList", "home", new { parentColumnUrl = Model.ArticleDetailModel.ParentColumnUrl, childColumnUrl = Model.ArticleDetailModel.EnTitle })/">@Model.ArticleDetailModel.ColumnName</a></span>@Model.ArticleDetailModel.ColumnName</h2>
        <h1 class="con_tilte">@Model.ArticleDetailModel.Title</h1>
        <p class="bloginfo">
            <i class="avatar"><img src="/image/avatar.jpg"></i><span></span><span>@Model.ArticleDetailModel.CreateTime</span><span></span><span>
                @Html.Raw(Model.ArticleDetailModel.Hits)人已围观
            </span>
        </p>
        <p class="con_info">
            <b>简介</b>@Model.ArticleDetailModel.Summary
        </p>
        <div class="con_text">
            @Html.Raw(WebHelper.DealwithContentImg(Model.ArticleDetailModel.Content))
            <p>
                Tags：
                @if (!string.IsNullOrEmpty(Model.ArticleDetailModel.Tag))
                {
                    var tags = Model.ArticleDetailModel.Tag.Replace('，', ',').Split(',');

                    for (int i = 0; i < tags.Length; i++)
                    {

                        <a href="@domainConfig.CurrentValue.Host@Url.Action("Search", "Home", new { keyword = tags[i] })" target="_blank"> @tags[i] </a>
                    }

                }
            </p>
            <p class="share"><b>转载：</b>感谢您对一起牛平台的认可，以及对我们原创作品以及文章的青睐，非常欢迎各位朋友分享到个人站长或者朋友圈，但转载请说明文章出处“一起牛”。</p>
            <p>
                <span class="diggit">
                    <a href="javascript:void(0)" id="btn-like"> 很赞哦!</a>
                    (<b id="diggnum">
                        @Model.ArticleDetailModel.Hits
                    </b>)
                </span>
            </p>
            <div class="nextinfo">
                @{
                    string upUrl = domainConfig.CurrentValue.Host;
                    string nextUrl = domainConfig.CurrentValue.Host;
                    @if (string.IsNullOrEmpty(Model.UpArticle?.ParentColumnUrl))
                    {
                        upUrl += $"/{Model.UpArticle?.EnTitle}/{Model.UpArticle?.Id}.html";
                    }
                    else
                    {
                        upUrl += $"/{Model.UpArticle?.ParentColumnUrl}/{Model.UpArticle.EnTitle}/{Model.UpArticle.Id}.html";
                    }
                    if (string.IsNullOrEmpty(Model.NextArticle?.ParentColumnUrl))
                    {
                        nextUrl += $"/{Model.NextArticle?.EnTitle}/{Model.NextArticle?.Id}.html";
                    }
                    else
                    {
                        nextUrl += $"/{Model.NextArticle?.ParentColumnUrl}/{Model.NextArticle?.EnTitle}/{Model.NextArticle.Id}.html";
                    }
                    <p>
                        上一篇：
                        @if (Model.UpArticle == null)
                        {
                            <a>暂无上篇信息</a>
                        }
                        else
                        {

                            <a href="@upUrl" title="@Model.UpArticle.Title">@Model.UpArticle.Title</a>
                        }
                    </p>
                    <p>
                        下一篇：
                        @if (ViewBag.NextId == null)
                        {
                            <a>暂无下篇信息</a>
                        }
                        else
                        {
                            <a href="@nextUrl" title="@Model.NextArticle.EnTitle">@Model.NextArticle.EnTitle</a>
                        }
                    </p>
                }
            </div>
        </div>
    </div>
    <div class="whitebg">
        <h2 class="htitle">相关文章</h2>
        <ul class="otherlink">
            @if (Model.SameColumnArticle.Count > 0 && Model.SameColumnArticle != null)
            {
                foreach (var item in Model.SameColumnArticle)
                {
                    string detailUrl = domainConfig.CurrentValue.Host;
                    @if (string.IsNullOrEmpty(item.ParentColumnUrl))
                    {
                        detailUrl += $"/{item.EnTitle}/{item.Id}.html";
                    }
                    else
                    {
                        detailUrl += $"/{item.ParentColumnUrl}/{item.EnTitle}/{item.Id}.html";
                    }
                    <li><a href="@detailUrl" title="@item.Title">@item.Title</a></li>
                }
            }
            else
            {
                <li style="text-align:center">暂无相关内容</li>
            }
        </ul>
    </div>
    <div class="whitebg gbook">
        <h2 class="htitle">文章评论</h2>
        <ul>
            <div class="fb">

            </div>
            <form action="" method="post" name="saypl" id="saypl">
                <div id="plpost">
                    <p class="saying">
                        <span>
                            <a class="msg-count">

                            </a>
                        </span>有话说,别藏着...
                    </p>
                    <p class="yname">
                        <span>邮箱:</span>
                        <input name="useremail" type="text" class="inputText" id="useremail" value="" size="16" style="border-radius: 5px; height: 25px;width: 230px; border: 1px solid #ccc">
                    </p>
                    <input name="nomember" type="hidden" id="nomember" value="1" checked="checked">
                    <textarea name="saytext" rows="6" id="saytext"></textarea>
                    <input name="imageField" id="btnOk" type="button" value="提交">
                </div>
            </form>
        </ul>
    </div>
</div>
@await Component.InvokeAsync("Right", new { ColumnParentSpell = Model.ArticleDetailModel.EnTitle })
<script type="text/javascript">
    $(function ()
    {
        $("#btn-like").click(function () {
            $.post('@Url.Action("LoadMessage","Home")', { newsId:'@Model.ArticleDetailModel.Id'}, function (data) {
                if (data == "ok") {
                    $("#diggnum").text(parseInt($("#diggnum").text()) + 1);
                }
            });
        });
        $("#btnOk").click(function () {
            var email = $("#useremail").val(), content = $("#saytext").val();
            var reg = /^([a-zA-Z]|[0-9])(\w|\-)+@@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
            if (email == "") {
                layer.msg("邮箱不能为空");
                return;
            }
            if (!reg.test(email)) {
                layer.msg("请填写正确的邮箱");
                return;
            }
            if (content == "") {
                layer.msg("您会留言吗");
                return;
            }
            var url ="@(@domainConfig.CurrentValue.ApiHost)/api/index/add-msg";
            $.post(url, { businessId: '@Model.ArticleDetailModel.Id', userName: email, content: content, types: "article",userName:email,siteId:'@(siteConfig.CurrentValue.GlobalSiteId)'}, function (data) {
                if (data.statusCode == 200) {
                    $("#useremail").val('');
                    $("#saytext").val('');
                    loadMessage();
                } else {
                    layer.msg("留言失败了");
                    return;
                }
            });
        });
        loadMessage();
    });
    function loadMessage() {

         var url ="@(domainConfig.CurrentValue.ApiHost)/api/h5/load-message";
        $.getJSON(url, { businessId: '@Model.ArticleDetailModel.Id',siteId:'@(siteConfig.CurrentValue.GlobalSiteId)',types:"article" }, function (data) {
            console.log(data);
            if (data != null) {
                var html = "";
                for (var i in data)
                    {
                    html +=('<ul><p class="fbtime"><span>' + data[i].createTime + '</span> ' + data[i].Email + '</p><p class="fbinfo">' + data[i].content + '</p></ul>');
                }
                $(".fb").html(html);
                $(".msg-count").html("共有"+data.length+"条评论")
            }
        });
    }
</script>

<script type="text/javascript">
    $('pre').addClass("line-numbers").css("white-space", "pre-wrap");
</script>